<?php

//防止恶意调用
if (!defined('IN_MOD'))
{
    die('Hacking attempt');
}

// 模块参数安装站点位置
if(!isset($configinfo['installmodule']))
{
	moduleerror(array("message"=>"Error:模块参数未知安装站点！请先安装！"));
}

// 开启session
if(session_start() !== PHP_SESSION_ACTIVE)
{
   session_start();
}

// 数据防灌水检查生成token session值
function tokencheckgenerate()
{
	global $_MGPC_REQ;
	
	if(isset($_MGPC_REQ['moduletoken']))
	{
	  if($_SESSION['moduletoken'] != $_MGPC_REQ['moduletoken'])
	  {
		  unset($_SESSION['moduletoken']); 
		  $_SESSION['moduletoken'] = rand(0,9).rand(0,9).rand(0,9).rand(0,9); 
	  }  
	}else{
	   unset($_SESSION['moduletoken']);// 每次访问删除seeion重置
	   $_SESSION['moduletoken'] = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
	}	
}
tokencheckgenerate();

/* 当前网址域名 */
$configinfo['weburl'] = "http://".$_SERVER['HTTP_HOST'];

// 当前网址参数
$configinfo['requrl'] = urldecode($_SERVER['REQUEST_URI']);

// 开启MVC框架模式
if($configinfo['mvc'] == 1)
{
	// 模板变量指向函数
	function smarty_assign($varname='',$var='')
	{
		return true;		
	}
}else{
	// 模板变量指向函数
	function smarty_assign($varname='',$var='')
	{
		configsmarty($varname, $var);
	}	
}

// 判断客户端
if($configinfo['modulepara'] == "frontend")
{
	$configinfo['webuser'] = "pc";// pc端
	$configinfo['modulepara'] = "pc";// pc端
	if(isMobileModule() == 1)
	{
		$configinfo['webuser'] = "mobile";// 手机端
		$configinfo['modulepara'] = "mobile";// 手机端与微信端（传统后台读取数据型式类型的手机端，微信端可以共用一个，使用mobile端的程序配置）
	}
	if(isWeixinModule() == 1)
	{
		$configinfo['webuser'] = "weixin";// 微信端
		$configinfo['modulepara'] = "mobile";// 手机端与微信端（传统后台读取数据型式类型的手机端，微信端可以共用一个，使用mobile端的程序配置）
	}
	if(isXcxModule() == 1)
	{
		$configinfo['webuser'] = "xcx";// 小程序端
		$configinfo['modulepara'] = "xcx";// 小程序端（API接口模式，以JS为后台，如网页使用JS通过API调用程序数据展示的，手机端，微信端，小程序端可以共用一个，使用当前xcx端的程序配置）
	}
}

// 当前模块
$configinfo['themodule'] = isset($configinfo['themodule']) ? $configinfo['themodule'] : "other";

// 模块多语言配置
if($configinfo['langok'] == 1)
{
	global $lang;
	
	// 模块默认语言
	if(moduleaqvarval('lang','string'))
	{
		$lang = $configinfo['lang'] = moduleaqvarval('lang','string');	
	}else{
		// 新增设置后台默认语言
		if($configinfo['modulepara'] == 'admin')
		{
			$lang = $configinfo['lang'] = $configinfo['adminlangdefault'];
		}else{
			$lang = $configinfo['lang'] = $configinfo['langdefault'];
		}
	}
	smarty_assign('lang',     $lang);
	// 开启MVC框架模式
	if($configinfo['mvc'] == 1)
	{
		$this->lang = $lang;
		$this->smarty_assign('lang',     $lang);
	}
}

// 扩展会员配置
$actopmember = $_MGPC_GET['act'];
if($actopmember == "member")$configinfo['membermodule'] = 1;
if($configinfo['expmember_ok'] == 1 && $configinfo['membermodule'] == 1)
{
	// 检测是否登录
	if(empty($configinfo['expmember_uid']))
	{
		moduleerror(array("message"=>"请先登录会员！","url"=>$configinfo['expmember_loginurl']));
	}
}

// 模块参数函数钩子配置
function modulehook($hookname='',$config="",$tpl=0)
{
	global $configinfo;
	
	$hookfun = "hook_".$hookname;
	
	// 加载模板程序配置
	if($configinfo['tplok'] == 1)
	{
		if($tpl == 1 || iffun("tplhook_".$hookname) == 1)
		{
			$hookfun = "tplhook_".$hookname;
		}
	}
	
	$hookdata = $hookfun($config);	
	
	return $hookdata;
}

// 获取调用模块数据钩子
// modname 配置栏目名
// config 当前配置数据
function modulehookdata($modname='',$config="")
{
	global $configinfo;
	
	$moduledata = '';
	
	if($modname)
	{
		$getmodname = "hook_".$modname;
		if(iffun($getmodname) == 1)
		{
			$moduledata = $getmodname($config);
		}
		
		// 加载模板程序配置
		if($configinfo['tplok'] == 1)
		{
			$gettplmodname = "tplhook_".$modname;
			if(iffun($gettplmodname) == 1)
			{
				$tpldata = $gettplmodname($config);
				if(is_array($moduledata))
				{
					$moduledata = hbarray($moduledata,$tpldata);
				}else{
					if(is_array($tpldata))
					{
						$moduledata = $tpldata['datahtml'];	
					}else{
						$moduledata .= $tpldata;	
					}
				}
			}
		}
	}
	
	return $moduledata;
}

/* 模块参数函数配置
** $modulewhere=array();
** $modulewhere[0]="zcj_news";
** $modulewhere[1]=443;
** $modulewhere[2]="aid";
** $test=modulepara("datainfo",$modulewhere);
*/
function modulepara($funname='',$para=array(),$type=0)
{
	global $configinfo;
	
	$modulepara="";
	
	if($type==1)
	{
		if($funname == "gettopclass")
		{
			$modulepara = gettopclass($configinfo['ecs_article_cat'], $para[0], $configinfo["cat_id"], $configinfo["parent_id"], $para[1]);
			
		}else if($funname == "getparentclass")
		{
			$modulepara = getparentclass($configinfo['ecs_article_cat'], $para[0], $configinfo["cat_id"], $configinfo["parent_id"]);
			
		}else if($funname == "getbottomclass")
		{
			$modulepara = getbottomclass($configinfo['ecs_article_cat'], $para[0], $configinfo["cat_id"], $configinfo["parent_id"], $para[1], $para[2]);
			
		}else if($funname == "getclassinfo")
		{
			$modulepara = getclassinfo($configinfo['ecs_article_cat'], $para[0], $configinfo["cat_id"], $configinfo["parent_id"], $para[1]);
			
		}else{
			$modulepara = $funname($para);	
		}
	}else{
		$i = 0;
		$paragroup = array();
		foreach($para as $key=>$val)
		{
			$i++;
			$paragroup[$i-1] = $val;
		}
		$modulepara = $funname($paragroup[0],$paragroup[1],$paragroup[2],$paragroup[3],$paragroup[4],$paragroup[5],$paragroup[6],$paragroup[7],$paragroup[8],$paragroup[9],$paragroup[10],$paragroup[11],$paragroup[12],$paragroup[13],$paragroup[14],$paragroup[15]);		
	}	

	return $modulepara;
}

/* 公用信息配置 */
global $configcommon,$configmember,$configbase,$configsystem,$configindex,$configother;
$configcommon=array();$configmember=array();$configbase=array();
$configsystem=array();$configindex=array();$configother=array();

/* 自定义区块 */
global $configblock;
if($configinfo['block'] == 1)
{
	$blockwhere=array();
	$blockwhere['tablename'] = $configinfo["ecs_article"];
	$blockwhere['arrayclass'] = array("tablename"=>$configinfo['ecs_article_cat'],"classid"=>$configinfo['zdyid'],"classidname"=>$configinfo['cat_id'],"parentidname"=>$configinfo['parent_id'],"classnamename"=>$configinfo['cat_name']);
	$blockwhere['bigclassname'] = $configinfo['article_cat_id'];
	$blockwhere['configname'] = $configinfo['title'];
	$blockwhere['dataidname'] = $configinfo['article_id'];
	$configblock = configblock($blockwhere);
	$systemconfig = datainfo($configinfo['ecs_article'],"系统信息配置",$configinfo['title']);
	$shopconfig = datainfo($configinfo['ecs_article'],"在线订购配置",$configinfo['title']);
	
	// 基本配置
	if(isset($configblock['网站基本配置']['网站基本配置']))$configbase['config'] = $configblock['网站基本配置']['网站基本配置'];
	if(isset($configblock['SEO基本配置']['SEO基本配置']))$configbase['seoconfig'] = $configblock['SEO基本配置']['SEO基本配置'];
	if(!empty($shopconfig))$configbase['shopconfig'] = $shopconfig;// 在线订购配置
	
	// 公用配置
	if(isset($configblock['网站公用信息']['网站公用信息']))$configcommon['info'] = $configblock['网站公用信息']['网站公用信息'];
	
	// 系统配置
	if(isset($configblock['公用内容代码']['公用内容代码']))$configsystem['html'] = $configblock['公用内容代码']['公用内容代码'];
	if(!empty($systemconfig))$configsystem['systemconfig'] = $systemconfig;// 系统信息配置
	
	// 首页配置
	if(isset($configblock['首页幻灯片']))$configindex['adv'] = $configblock['首页幻灯片'];
	if(isset($configblock['首页区块内容']['首页区块内容']))$configindex['block'] = $configblock['首页区块内容']['首页区块内容'];
}

// 加载系统数据配置
if(count($configdata) > 0)$configsystem += $configdata;

// 加载模块参数基本配置
if($configinfo['info'] && $configinfo['installmodule'] == "default")require(MODULEPARA_PATH . '/modulepara-'.VERSION_NUMBER.'/config/moduleinfo.php');

// 加载模块参数模块配置
if($configinfo['info'] && $configinfo['config'] && $configinfo['installmodule'] == "default")require(MODULEPARA_PATH . '/modulepara-'.VERSION_NUMBER.'/config/modulepara.php');

// 网站过期时间
if($configinfo['websiteok'] == 1)
{	
	if($configinfo['modulepara'] != "admin")
	{
		websitetime($configinfo['website_starttime'],$configinfo['website_endtime']);
	}
}

// 开启MVC框架模式
if($configinfo['mvc'] == 1)
{
	$this->_MGPC_POST = $_MGPC_POST;
	$this->_MGPC_GET = $_MGPC_GET;
	$this->_MGPC_REQ = $_MGPC_REQ;
	$this->_MGPC_COOKIE = $_MGPC_COOKIE;
	$this->_MGPC_SESSION = $_MGPC_SESSION;
	$this->configlang = $configlang;
	$this->configinfo = $configinfo;
	$this->configblock = $configblock;
	$this->configcommon = $configcommon;
	$this->configmember = $configmember;
	$this->configbase = $configbase;
	$this->configsystem = $configsystem;
	$this->configindex = $configindex;
	$this->configother = $configother;
}
?>